Vue.filter("statusText", function(value){
    var status;
    if(value==0){
        status="正在请求";
    }else if(value==1) {
        status ="请求失败";
    }else if(value==2){
        status ="请求成功";
    }else if(value==3){
        status="下发失败"
    }else if(value==4){
        status = "下发成功";
    }else if(value==5){
        status = "数据解析错误";
    }
    return status;
})

Vue.filter("date", function(time) {
    var now = new Date(time);
    var year = now.getFullYear();
    var month = now.getMonth() + 1;
    var date = now.getDate();
    var hour = now.getHours();
    var minute = now.getMinutes();
    var second = now.getSeconds();
    return year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
})

var messageDetail = new Vue({
    el: '#messageDetail-list',
    data: {
        list: [],
    },
})
layui.use(['table','form', 'layedit', 'laydate','jquery','laypage'], function () {
    var table = layui.table
        ,form = layui.form
        ,layer = layui.layer
        ,layedit = layui.layedit
        ,laydate = layui.laydate
        ,$ = layui.jquery
        ,laypage = layui.laypage;
    //监听表格复选框选择
    table.on('checkbox(demo)', function (obj) {
        console.log(obj)
    });
    //监听工具条
    table.on('tool(demo)', function (obj) {
        var data = obj.data;
        if (obj.event === 'detail') {
            layer.msg('ID：' + data.id + ' 的查看操作');
        } else if (obj.event === 'del') {
            layer.confirm('真的删除行么', function (index) {
                obj.del();
                layer.close(index);
            });
        } else if (obj.event === 'edit') {
            layer.alert('编辑行：<br>' + JSON.stringify(data))
        }
    });

    var $ = layui.$, active = {
        getCheckData: function () { //获取选中数据
            var checkStatus = table.checkStatus('idTest')
                , data = checkStatus.data;
            layer.alert(JSON.stringify(data));
        }
        , getCheckLength: function () { //获取选中数目
            var checkStatus = table.checkStatus('idTest')
                , data = checkStatus.data;
            layer.msg('选中了：' + data.length + ' 个');
        }
        , isAll: function () { //验证是否全选
            var checkStatus = table.checkStatus('idTest');
            layer.msg(checkStatus.isAll ? '全选' : '未全选')
        }
    };

    $('.demoTable .layui-btn').on('click', function () {
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });
    getDate();


    function getDate(){
        $.ajax({
            type: "get",
            url: ctx+"/msgdetail/selectListByUserId.do",
            contentType: "application/json",
            async: false,
            success: function (res) {
                console.log(res);
                if (res.resultCode == 10000) {
                    messageDetail.list=res.data;
                } else {
                    layer.msg(res.msg, {icon: 1});
                }
            },
        });
    }

    //调用分页
    var data = messageDetail.list;
    laypage.render({
        elem: 'page'
        ,count: messageDetail.list.length
        ,limit:5
        ,jump: function(obj){
            messageDetail.list = data.concat().splice(obj.curr*obj.limit - obj.limit, obj.limit);
        }
    });

    $('#add').on('click',function () {
        layer.open({
            type: 2,
            title: ['短信下发', 'font-size:13px;margin-top:10px;text-align:center'],
            content: ctx+'/msgdetail/sendMessagePage.do',//con是Ajax返回的页面
            // btn: ['确定', '取消'],
            area: ['400px', '350px'],
            shade: false,
            maxmin: true,
            anim: 2,

        })
    });

});

